package com.qch.kafka.demo.serialization;

import com.qch.kafka.demo.entity.User;
import org.apache.kafka.common.serialization.Deserializer;

import java.nio.ByteBuffer;
import java.util.Map;

/**
 * @Author qch
 * @Date 2021/5/31
 */
public class UserDeserializer implements Deserializer {
    public void configure(Map map, boolean b) {

    }

    public Object deserialize(String s, byte[] data) {
        ByteBuffer buffer=ByteBuffer.allocate(data.length);
        buffer.put(data);
        //指针进行反转
        buffer.flip();
        int userId = buffer.getInt();
        int usernameLength = buffer.getInt();
        String username = new String(data, 8, usernameLength);
        return new User(username,userId);
    }

    public void close() {

    }
}
